<template>
	<!-- 修改缴费信息 -->
	<div class="stu">
		<el-dialog v-loading="loading" :title="num==0?'新增缴费信息':'修改缴费信息'" :visible.sync="dialogVisible" width="35%"
		 :before-close="handleClose" :close-on-click-modal='false'>
			<div style="width:100%;padding-left:20px;padding-bottom:30px;">
				<div class="tabs">
					<div class="pbox"><a>* </a>地区</div>
					<el-select @change='group_name="";' style='width:34.5%;' v-model="activess.village_name" clearable filterable
					 placeholder="请选择行政村">
						<el-option v-for='i in $store.state.cunid' :label="i.label" :value="i.label"></el-option>
					</el-select>
					<el-select v-model="activess.group_name" style='width:34.5%;' clearable filterable placeholder="请选择村组">
						<el-option v-for='i in activeput(activess.village_name,$store.state.cunzuid)' :label="i.label" :value="i.label"></el-option>
					</el-select>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>门牌号码</div>
					<el-input class='tabinp' v-model="activess.number" placeholder="请输入" clearable></el-input>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>姓名</div>
					<el-input class='tabinp' v-model="activess.name" placeholder="请输入" clearable></el-input>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>身份证号</div>
					<el-input class='tabinp' v-model="activess.card" placeholder="请输入" clearable></el-input>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>是否在家</div>
					<el-radio v-model="activess.is_stay" label="1">是</el-radio>
					<el-radio v-model="activess.is_stay" label="0">否</el-radio>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>是否缴纳费用</div>
					<el-radio @change='activess.is_pay==0?activess.pay_ment=0:activess.pay_ment=""' v-model="activess.is_pay" label="1">是</el-radio>
					<el-radio @change='activess.is_pay==0?activess.pay_ment=0:activess.pay_ment=""' v-model="activess.is_pay" label="0">否</el-radio>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>卫生费金额</div>
					<el-input :disabled='activess.is_pay==0' class='tabinp' v-model="activess.pay_ment" placeholder="请输入" type='number'
					 min='0' clearable></el-input>
				</div>
				<div class="tabs">
					<div class="pbox"><a>* </a>缴纳日期</div>
					<el-date-picker v-model="activess.pay_time" value-format='yyyy-MM-dd' type="date" placeholder="选择日期" clearable
					 class='tabinp'></el-date-picker>
				</div>
			</div>
			<div style="width:100%;height:40px;margin-top:20px;">
				<div style="width:170px;margin: 0 auto;">
					<el-button type="danger" @click="handleClose">取 消</el-button>
					<el-button style='float:right;' type="primary" @click="git_acts">确 定</el-button>
				</div>
			</div>
		</el-dialog>

	</div>
</template>

<script>
	import $ from 'jquery'
	export default {
		name: 'stu',
		components: {}, //声明子组件
		computed: {
			activeput() { //联动判断，code 为上一级的code  act为当前未赛选的数据字典
				return function(code, act) {
					let a = [];
					for (let i = 0; i < act.length; i++) {
						if (act[i].own_village == code) {
							a.push(act[i]);
						}
					}
					return a;
				}
			},
			gitcode() { //通过id获取code
				return function(id, act) {
					for (let i = 0; i < act.length; i++) {
						if (id == act[i].value) {
							return act[i].code;
							break
						}
					}
				}
			},
			date_va() {
				return function(das) {
					let da = Math.floor(das / 2);
					let year = new Date().getFullYear() //年
					let month = new Date().getMonth() + 1 //月
					let date = new Date().getDate() //日
					month += da;
					let mon = Math.floor(month / 12);
					if (month > 12) {
						if (mon > 1) {
							year += mon;
							month = month - (mon * 12);
						} else {
							year += 1;
							month = month - 12;
						}
					}
					return year + '-' + month + '-' + date;
				}
			}
		},
		data() {
			return {
				loading: false,
				btn_shou: false,
				dialogVisible: false,
				dialogVisible2: false,
				activess: {
					id: '', //主键
					number: '', //门牌号码
					village_name: '', //村名
					group_name: '', //组名
					name: '', //姓名
					is_stay: '', //是否在家(1是 0否)
					card: '', //身份证号码
					is_pay: '', //是否已经缴纳费用(1是 0否)
					pay_ment: '', //卫生费金额
					pay_time: '', //缴纳日期(exp:2020-05-20)
					effective_time: '',
				},
				renbox: [],
				num: '',
				ader: [],
			}
		},
		methods: {
			git_act(i, num) { //获取数据的同打开狂口
				if (num == 1) {
					this.activess = i;
					this.activess.is_stay = this.activess.is_stay + '';
					this.activess.is_pay = this.activess.is_pay + '';
				}
				this.num = num;
				console.log(this.activess, num);
				this.dialogVisible = true;
			},
			git_acts() { //提交数据
				console.log(this.activess.pay_ment)

				if (this.isNull(this.activess.village_name)) {
					this.$message.error('请输入 行政村');
					return false
				}
				if (this.isNull(this.activess.group_name)) {
					this.$message.error('请输入 村组');
					return false
				}
				if (this.isNull(this.activess.number)) {
					this.$message.error('请输入 门牌号码');
					return false
				}
				if (this.isNull(this.activess.name)) {
					this.$message.error('请输入 姓名');
					return false
				}
				if (this.isNull(this.activess.card)) {
					this.$message.error('请输入 身份证号码');
					return false
				}
				if (this.iscard(this.activess.card)) {
					this.$message.error('身份证号 格式不正确');
					return false
				}
				if (this.isNull(this.activess.is_stay)) {
					this.$message.error('请选择 是否在家');
					return false
				}
				if (this.isNull(this.activess.is_pay)) {
					this.$message.error('请选择 是否缴纳费用');
					return false
				}
				if (this.activess.pay_ment != '' || this.activess.pay_ment === 0) {} else {
					this.$message.error('请输入 卫生费金额');
					return false
				}
				if (this.activess.is_pay == 1) {
					if (this.activess.pay_ment > 0) {} else {
						this.$message.error('输入的卫生费金必须大于零');
						return false
					}
				}
				if (this.isNull(this.activess.pay_time)) {
					this.$message.error('请选择 缴纳日期');
					return false
				}

				this.activess.effective_time = this.date_va(this.activess.pay_ment);

				let url = this.num == 1 ? '/xf/point_pc/payment_modify' : '/xf/point_pc/payment_insert';
				$.ajax({
					url: url,
					type: 'post',
					data: this.activess,
					dataType: 'json',
					success: (res) => {
						if (Object.prototype.toString.call(res) != '[object Object]') {
							res = JSON.parse(res)
						}
						console.log(res, '提交');
						if (res.code == 200) {
							this.$parent.git_activa();
							this.$message({
								message: '操作成功',
								type: 'success'
							});
							this.dialogVisible = false;
							this.qin();
						} else {
							this.$message.error(res.msg);
						}
					}
				})
			},

			qin() { //清除
				this.activess = {
					number: '', //门牌号码
					village_name: '', //村名
					group_name: '', //组名
					name: '', //姓名
					is_stay: '', //是否在家(1是 0否)
					card: '', //身份证号码
					is_pay: '', //是否已经缴纳费用(1是 0否)
					pay_ment: '', //卫生费金额
					pay_time: '', //缴纳日期(exp:2020-05-20)
					effective_time: '',
				};
				this.ader = [];
			},
			handleClose(done) { //监测用户点击x
				this.$confirm('确定取消关闭吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$parent.git_activa();
					this.dialogVisible = false;
					this.qin();
				}).catch(() => {});
			},

		},
		mounted() {
			// this.git_ren()
		}
	}
</script>
<style scoped="scoped">
	.tabinp {
		width: 70%;
		float: left;
	}

	.pbox a {
		color: red;
	}

	.pbox {
		float: left;
		width: 110px;
		height: 100%;
		margin-right: 15px;
		text-align: right;
	}

	.tabs {
		width: 100%;
		height: 45px;
		line-height: 45px;
		font-size: 15px;
		margin-bottom: 10px;
	}
</style>
